package com.sangmo.fts.api.inventory;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.common.security.meta.Access;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.process.inventory.interfaces.IfLadingBillDocumentRequest;
import com.sangmo.fts.process.inventory.service.IfLadingBillDocumentService;
import com.sangmo.fts.restructure.meta.TrainingApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

@TrainingApi
@Controller
@RequestMapping(value = "/ifLadingBill/v1")
@Access("ifLadingBill")
public class IfLadingBillDocumentApi {

    @Autowired
    private IfLadingBillDocumentService ifLadingBillDocumentService;

    /** 上传提货申请书 **/
    @Access(":applyUpload")
    @PostMapping({"/{trainingId}/{id}/apply/document/upload"})
    @ResponseBody
    public ApiResponse<FileUpload> createApplyDoc(@PathVariable("trainingId") Long trainingId, @PathVariable("id") Long id, @RequestBody @Valid IfLadingBillDocumentRequest request) {
        return ApiResponse.make(ifLadingBillDocumentService.createBillApplyDoc(id, request.getFileUploadId()));
    }

    /*@PostMapping({"/{trainingId}/{id}/apply/document/remove"})
    @ResponseBody
    public ApiResponse<FileUpload> removeApplyDoc(@PathVariable("trainingId") Long trainingId, @PathVariable("id") Long id) {
        ifLadingBillDocumentService.remove(id);
        return ApiResponse.make();
    }*/

    /** 上传提货通知书 **/
    @Access(":confirmUpload")
    @PostMapping({"/{trainingId}/{id}/confirm/document/upload"})
    @ResponseBody
    public ApiResponse<FileUpload> createConfirmDoc(@PathVariable("trainingId") Long trainingId, @PathVariable("id") Long id, @RequestBody @Valid IfLadingBillDocumentRequest request) {
        return ApiResponse.make(ifLadingBillDocumentService.createBillConfirmDoc(id, request.getFileUploadId()));
    }

    /** 上传提货通知书回执 **/
    @Access(":receiptUpload")
    @PostMapping({"/{trainingId}/{id}/receipt/document/upload"})
    @ResponseBody
    public ApiResponse<FileUpload> createReceiptDoc(@PathVariable("trainingId") Long trainingId, @PathVariable("id") Long id, @RequestBody @Valid IfLadingBillDocumentRequest request) {
        return ApiResponse.make(ifLadingBillDocumentService.createBillReceiptDoc(id, request.getFileUploadId()));
    }

}
